import { _decorator, Button, Component, instantiate, Label, Node, Prefab, Sprite, SpriteFrame } from 'cc';
import { RendorManager } from '../Base/RendorManager';
import { ItemStatusEnum, ItemTypeEnum, TriggerTypeEnum } from '../Enum';
import { TriggerManager } from './TriggerManager';
import DataManger from '../RunTime/DataManager';

const { ccclass, property } = _decorator;

@ccclass('MailBoxTriggerManager')
export class MailBoxTriggerManager extends TriggerManager{
    type: TriggerTypeEnum = TriggerTypeEnum.MailBox
    
    @property(Node)
    openNode: Node = null
    
    @property(Node)
    closeNode: Node = null

    rendor(): void {
        super.rendor()
        this.closeNode.active = !DataManger.Instance.isMailBoxOpen
        this.openNode.active = DataManger.Instance.isMailBoxOpen
        
    }

    handleTrigger() {
        if (DataManger.Instance.curItemType === ItemTypeEnum.Key && DataManger.Instance.isSelect) {
            //一些复位：curItem,isSelect
            DataManger.Instance.curItemType = null
            DataManger.Instance.isSelect = false
            //Item状态改变
            DataManger.Instance.items.find(i => i.type === ItemTypeEnum.Key).status = ItemStatusEnum.Disable
            DataManger.Instance.items.find(i => i.type === ItemTypeEnum.Mail).status = ItemStatusEnum.Scene
            DataManger.Instance.items = [...DataManger.Instance.items]
    
            DataManger.Instance.isMailBoxOpen = true
        }
    }

}